package Collecion;

import java.util.Comparator;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

public class Demo {
    public static void main(String[] args) {
        Set<Person> set = new HashSet<>();
        set.add(new Person("张三", 11));
        set.add(new Person("李四", 20));
        set.add(new Person("张三", 20));
        System.out.println(set);
    }

    private static void TEXT1() {
        Set<String> set = new HashSet<>();
        set.add("张三");
        set.add("李四");
        set.add("赵六");
        set.add("王五");
        for (String s : set) {
            System.out.println(s);
        }
    }
}

class Person implements Comparable<Person> {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person() {
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name,age);
    }

    @Override
    public int compareTo(Person person) {
        return this.name.compareTo(person.getName());
    }
}
class MyComparetor implements Comparator<Person>{

    @Override
    public int compare(Person o1, Person o2) {
        return  o1.getAge()-o2.getAge();
    }
}